part of 'widget.dart';

class _UserProgressBlockView extends StatelessWidget with ScreenUtilMixin {
  const _UserProgressBlockView({
    required _UserProgressBlockWloc wloc,
  }) : _wloc = wloc;

  final _UserProgressBlockWloc _wloc;

  double get _scaleFactor {
    return min(widthScaleFactor, logWidthScaleFactor);
  }

  Widget _buildContent({
    required _UserProgressBlockWlocState state,
    required BuildContext context,
  }) {
    return Padding(
      padding: EdgeInsets.symmetric(
        vertical: 12 * _scaleFactor,
      ),
      child: Row(
        children: [
          SizedBox(
            width: 16 * _scaleFactor,
          ),
          ClipOval(
            child: Image.asset(
              'assets/images/levels/${state.levelIndex + 1}.jpg',
              width: 85 * _scaleFactor,
              height: 85 * _scaleFactor,
              fit: BoxFit.contain,
              alignment: Alignment.center,
              filterQuality: FilterQuality.medium,
            ),
          ),
          SizedBox(
            width: 16 * _scaleFactor,
          ),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  UserProgressBlockTranslation.of(context).buildPointCountLabel(
                    pointCount: state.pointCount,
                  ),
                  style: UserProgressBlockTheme.of(context).textTheme.pointCountLabel,
                  textScaleFactor: _scaleFactor,
                ),
                SizedBox(
                  height: 10 * _scaleFactor,
                ),
                LinearProgressBar(
                  thickness: 9.5 * _scaleFactor,
                  progress: state.nextLevelProgressRatio,
                  roundedCap: true,
                  progressColor: CoreTheme.of(context).primaryColor,
                  backgroundColor: CoreTheme.of(context).progressIndicatorBackgroundColor,
                ),
                SizedBox(
                  height: 10 * _scaleFactor,
                ),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      UserProgressBlockTranslation.of(context).buildLevelNumberLabel(
                        levelNumber: state.levelIndex + 1,
                      ),
                      style: UserProgressBlockTheme.of(context).textTheme.levelNumberLabel,
                      textScaleFactor: _scaleFactor,
                    ),
                    if (!state.lastLevelReached)
                      Expanded(
                        child: Padding(
                          padding: EdgeInsets.only(
                            left: 12 * _scaleFactor,
                          ),
                          child: SizedBox(
                            width: double.infinity,
                            child: Text(
                              UserProgressBlockTranslation.of(context)
                                  .buildNextLevelRemainingPointCountInfo(
                                remainingPointCount: state.nextLevelRemainingPointCount!,
                                nextLevelNumber: state.levelIndex + 2,
                                compacted: ScreenUtil().screenLayout.isPhoneLayout,
                              ),
                              style: UserProgressBlockTheme.of(context)
                                  .textTheme
                                  .nextLevelRemainingPointCountInfo,
                              textScaleFactor: _scaleFactor,
                              textAlign: TextAlign.right,
                            ),
                          ),
                        ),
                      ),
                  ],
                ),
              ],
            ),
          ),
          SizedBox(
            width: 16 * _scaleFactor,
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return RoundedTileGroup(
      tiles: [
        Container(
          color: CoreTheme.of(context).tileColor,
          child: WlocBuilder<_UserProgressBlockWloc, _UserProgressBlockWlocState>(
            wloc: _wloc,
            builder: (context, state) {
              return _buildContent(
                state: state,
                context: context,
              );
            },
          ),
        ),
      ],
    );
  }
}
